<?php
/**
 * 藏品列表模板
 * User: crstu
 * Date: 2016/5/3
 * Time: 11:06
 */

use kartik\grid\GridView;
use yii\helpers\Html;

$this->title = '商品列表';


$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],

    'title',
    [
        'label' => '商品类型',
        'attribute' => 'typeID',
        'value' => 'productType.typeName',
        'filter' =>   \yii\helpers\ArrayHelper::map(\common\models\DAO\ProductType::find()-> select("id,typeName") -> asArray()->all(),'id','typeName'),
    ],
    [
        'attribute' => 'price',
        'value' => function($model){
            return $model->price/100;
        }
    ],

    [
        'attribute' => 'status',
        'format' => 'html',
        'value' => function($model){

            if($model->status === 0){
                return Html::tag('span', '正常', ['class'=>'label label-default']);
            }elseif ($model->status === 1){
                return Html::tag('span', '下架', ['class'=>'label label-success']);
            }else{
                return '';
            }
        },
        'filter' => [
            0 => '正常',
            1 => '下架',

        ]
    ],
    [
        'attribute' => 'rec',
        'format' => 'html',
        'value' => function($model){

            if($model->rec === 0){
                return Html::tag('span', '否', ['class'=>'label label-default']);
            }elseif ($model->rec === 1){
                return Html::tag('span', '是', ['class'=>'label label-success']);
            }else{
                return '';
            }
        },
        'filter' => [
            0 => '否',
            1 => '是',

        ]
    ],
    'sort',
    [
        'attribute' => 'adminID',
        'value' => 'admin.realName',
    ],
    [
        'format' => 'datetime',
        'attribute' => 'createTime',
        'filterType' => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => [
            'presetDropdown' => true,
            'pluginOptions' => [
                'locale' => [
                    'format' => 'YYYY/MM/DD',
                    'separator' => ' ~ ',
                    'language' => 'zh-CN',
                ]
            ],
            'pluginEvents' => [
                "apply.daterangepicker" => "function(){ aplicarDateRangeFilter('createTime') }",
            ],
        ],
    ],
    [
        'class' => 'common\widgets\KartikActionColumn',
        'items' => [
            ['编辑', 'product/edit', 'btn-primary'],
            ['删除', 'product/del', 'btn-danger'],
            ['管理图集', 'product-thumb/list', 'btn-primary'],
        ]
    ]
];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'toolbar' => [
        ['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> 添加产品', ['product/add'], ['class' => 'btn btn-primary'])],
        '{toggleData}'
    ],
    'panel' => [
        'type' => GridView::TYPE_DEFAULT,
        'heading' => $this->title,
    ],
    'columns' => $gridColumns,
]);